<?php


namespace app\api\controller\v35;

use app\api\controller\v2\Auth;
use app\common\cachemodel\FortuneNote;
use app\common\cachemodel\lucky\AppLuckyTaskRecord;
use app\common\cachemodel\zl2\Zl2FortuneTarotCard;
use app\common\lib\astrolog\Astrolog;
use app\common\lib\horoscope\Horoscope as HoroscopeData;
use app\common\lib\Util;
use app\common\model\FortuneCache;
use app\common\model\Recode;
use think\Env;

class Fortune extends Auth
{
    protected $active_switch;

    public function _initialize()
    {
        parent::_initialize();
        $this->active_switch = false;
    }

    /**
     * @title 每日运势详情
     * @method GET
     * @desc
     * @return \think\response\Json
     * @throws \app\common\lib\exception\ApiException
     */
    public function index()
    {
        $rid = input('get.rid/d', 0);
        // 当前时间
        $time = strtotime(input('get.time/s'));

        if (!$rid)
        {
            return show(config('code.error'), '档案信息获取失败');
        }
        $uid = (int)$this->user['id'];

        $recode = (new Recode())->getRecode(['id' => $rid]);
        if (!$recode || $recode['uid'] != $this->user['id'])
        {
            return show(config('code.error'), '档案不存在');
        }

        //获取日运详情数据
        $data = (new FortuneCache())->getIndexInfo($uid, $time, $rid, $this->active_switch, 3);

        if (isset($data['fortune_list']))
        {   // 已解锁
            $data = $this->fortuneDataReset($data, $recode, $time);
        }

        // 按照 2.9.4 版本 接口自动完成每日任务    浏览日运
        $date = date('Ymd');
        if ($rid === $this->user['rid'] && date('Ymd', $time) === $date && $this->headers['app-type'] === 'android' && Util::CheckAppVersion('2.9.4') === '同')
        {
            $luckyTaskConfig = config('lucky_task');
            $taskId = 2; // 浏览日运
            if (in_array($taskId, $luckyTaskConfig['everyday'], true))
            {   // 当前任务在每日任务里面
                $luckyTaskRecordModel = new AppLuckyTaskRecord();
                // 获取每日任务完成 信息
                $taskSuccessInfo = $luckyTaskRecordModel->getEverydayTaskSuccessData($this->user['id'], $date);
                if (!isset($taskSuccessInfo[$taskId]))
                {   // 任务未完成 去完成任务
                    $res = $luckyTaskRecordModel->setEverydayTaskSuccess($this->user['id'], $date, $taskId);
                    if ($res)
                    {// 任务已完成
                        $data['lucky_toast'] = [
                            "title" => $luckyTaskConfig['task_list'][$taskId]['toast_name'],
                            "img" => $luckyTaskConfig['task_list'][$taskId]['img'],
                            "des" => "x{$luckyTaskConfig['task_list'][$taskId]['lucky_num']}可领取"
                        ];
                    }
                }
            }
        }

        $oss = Env::get('host.photo');
        $date = date('Y-m-d', $time);
        $data['button_list'] = [];
        //今日有自己的档案
        if ($this->user['rid'] == $rid)
        {   // 查看自己的运势
            $dateInt = (int)date('Ymd', $time);
            $n = $dateInt - date('Ymd');

            $moodNoteBtn = [
                'icon' => $oss . '/test/fortune/mood_edit.png',
                'title' => $n === 0 ? '查看今日的心情' : '查看当日的心情',
                'target' => 'local',
                'link' => "mood_index?date={$date}&need_auth=2",
            ];

            if (in_array($n, [0, -1, -2], true) && !(new FortuneNote())->dateIsSetNote($this->user['id'], $date))
            {
                $moodNoteBtn['title'] = $date === date('Y-m-d') ? '记录今日的心情' : '记录当日的心情';
            }
        }

        //获取心情签到信息
        if (isset($moodNoteBtn))
        {
            $data['button_list'][] = $moodNoteBtn;
        }
        $data['button_list'][] = [
            'icon' => $oss . '/test/fortune/port_img.png',
            'title' => '生成专属海报',
            'target' => '',
            'link' => '',
        ];
        return show(200, '加载成功', $data);
    }

    /**
     * 运势信息新增厄运消除数据结构
     * @param array $data
     * @param array $recode
     * @param int $time
     * @return array
     * @throws \Exception
     */
    private function fortuneDataReset(array $data, $recode, int $time): array
    {
        $testName = '';
        foreach ($data['revive_day'] as $index => $reviveDayItem)
        {
            $new_icon = explode('/', $reviveDayItem['icon_url']);

            $testName = $testName ?: $reviveDayItem['name'];
            array_splice($new_icon, 5, 0, ['v3']);

            $data['revive_day'][$index]['icon2_url'] = implode('/', $new_icon);
        }

//        foreach ($data['fortune_list'] as $k => $datum)
//        {   // todo 运势提点标识
//            if ($k > 0 || empty($testName))
//            {
//                $data['fortune_list'][$k]['tip_icon'] = '';
//                $data['fortune_list'][$k]['tip_location_text'] = '';
//            } else
//            {
//                $data['fortune_list'][$k]['tip_icon'] = '/test/fortune/fortune_list_icon_1_1.png';
//                $data['fortune_list'][$k]['tip_location_text'] = $testName;
//            }
//        }

        if ($recode['isself'] && (date('Ymd', $time) === date('Ymd')))
        {
//            $data['poster_title'] = [
//                'title' => 'DIY专属海报',
//                'desc' => '去分享自己亲手设计的准了海报吧！～',
//                'is_new' => 1,
//            ];
            $data['poster_title'] = '生成专属海报';

            // 获取用户当天抽牌记录
            $fortuneTarotCardModel = (new Zl2FortuneTarotCard());
            $cardInfoId = $fortuneTarotCardModel->getCardIdByToday($this->user['id'], (int)date('Ymd'));
            $cardInfo = $fortuneTarotCardModel->getInfoById($cardInfoId, ['card_id']);
            if(Util::AppIsPassShowV1())
            {
                $data['transport_tool'] = null;
                $data['guess_list'] = [];
            }else
            {
                if (Util::IsHuaweiAndOppo()) {
                    $data['transport_tool'] = [
                        'title' => '提点小工具',
                        'card' => [
                            'img' => $cardInfoId > 0 ? "/test/tarot/cards/{$cardInfo['card_id']}-1.png" : '/test/tarot/cards/default_card.png',
                            'title' => '卡牌',
                            'des' => $cardInfoId > 0 ? '明天再来～' : '让卡牌给你建议',
                            'target' => 'local',
                            'link' => $cardInfoId > 0 ? "fortune_increase_card_detail?id={$cardInfoId}&need_auth=2" : 'fortune_increase_card_select?need_auth=2'
                        ],
                        'lucky_tie' => [
                            'title' => '幸运结缘',
                            'des' => '和ta互动来改善状态',
                            'target' => 'local',
                            'link' => 'lucky_ranking?need_auth=1'
                        ],
                    ];
                } else {
                    $data['transport_tool'] = [
                        'title' => '转运小工具',
                        'card' => [
                            'img' => $cardInfoId > 0 ? "/test/tarot/cards/{$cardInfo['card_id']}-1.png" : '/test/tarot/cards/default_card.png',
                            'title' => '转运卡牌',
                            'des' => $cardInfoId > 0 ? '明天再来～' : '让卡牌给你运势建议',
                            'target' => 'local',
                            'link' => $cardInfoId > 0 ? "fortune_increase_card_detail?id={$cardInfoId}&need_auth=2" : 'fortune_increase_card_select?need_auth=2'
                        ],
                        'lucky_tie' => [
                            'title' => '幸运结缘',
                            'des' => '和ta互动来改善运势',
                            'target' => 'local',
                            'link' => 'lucky_ranking?need_auth=1'
                        ],
                    ];
                }
            // 获取猜你想问
//            $guessQuestionList = (new GuessQuestion())->getDataList();
//            $data['guess_list'] = $guessQuestionList;
                $data['guess_list'] = $this->getRecomendQuestion($recode, $time, $data['fortune_list']);
            }
        }
        return $data;
    }

    private function getRecomendQuestion($recode, $time, $fortune_list)
    {
        /**
         * 财富
         *   我的财运何时会好转
         *      财运为困难，第一名
         *      男，财运为第一名
         *   我能赚到很多钱吗
         *      本命有三颗以上星在2宫，财运警戒以下
         *      本命金星被土星刑冲，财运警戒以下
         *   我什么时候能发财
         *      本命有三颗以上星在2宫，财运警戒以下
         *      本命金星被土星刑冲，财运警戒以下
         *   我适合炒股投资吗
         *      本命有三颗以上星体在8宫，财运警戒以下
         *      八字天干或地支本气有劫财，财运警戒以下
         * 婚恋
         *   我什么时候有桃花
         *      女，婚恋运平平以下
         *   我什么时候能遇到好的缘分
         *      女，婚恋运平平以下
         *      金星被土天海冥之一刑冲，婚恋运平平以下
         *   我的另一半是什么样的
         *      22岁以下
         *   什么样的人会喜欢我
         *      女，婚恋运平平以下
         *      金星被土星刑冲，婚恋运平平以下
         *   我的感情运何时变好
         *      女，婚恋运警戒以下
         *   我喜欢的人喜欢我吗
         *      女，土星5宫或土星金星成相或土星火星成相，28岁以下
         *      女，22岁以下
         *   我该怎么和喜欢的人相处
         *      金星被任意星刑冲
         *      月亮被任意星刑冲
         *      婚恋60分以上
         *   他还会回来找我吗
         *      女，日月升金火之一在巨蟹或双鱼，婚恋警戒以下
         *      女，三限金星刑冲冥王，本命日月升金火之一在双鱼或巨蟹或金星与海王成相
         * 事业
         *   我适合做什么工作
         *      20岁以上，24岁以下，事业运警戒以下
         *   我什么时候能有好的事业发展
         *      男，事业运警戒以下
         *      女，事业运第一且警戒以下
         *   我适合创业吗
         *      八字原局有七杀或本气七杀
         *   我的未来事业高度怎样
         *      男，日月金木水火土之一在10宫
         *      男，八字有官杀或本气官杀
         *   我适合换工作吗
         *      三限月亮与天王海王同时成相位
         *      三限月亮在6/8/10宫与天王或海王成相
         * 学业
         *   我要继续读书吗
         *      23岁以上，日月木土之一在9宫
         *   我需要学一些什么
         *      土星在39宫
         *      本命日月升之一在双子座
         *   我适合学习占星吗
         *      本命日月升有处女、天蝎或水瓶、双鱼，89或12宫有日月水命主之一
         *      本命水星落8宫
         */
        // 获取本命盘，三限盘，八字
        $timeinfo = [
            'year' => (int)(date('Y', $time)),
            'month' => (int)(date('m', $time)),
            'day' => (int)(date('d', $time)),
            'hour' => (int)(date('H', $time)),
            'minute' => (int)(date('i', $time)),
            'timezone' => 8, // 默认北京时间
            'is_summer' => 0,
        ];
        $astro = Astrolog::getInstance()
            ->setRecode1($recode)
            ->setAdvance($timeinfo)
            ->setExecPrefix(config('astrolog.prefix'))
            ->setIsAstrolabe(false)
            ->setUserSetting(config('astroset.setting1'))
            ->setGetDatas(['natal', 'thirdprogressed'])
            ->getAstroDatas();
        $natal = json_decode(json_encode($astro->getDatas('natal')), true);
        $thirdprogressed = json_decode(json_encode($astro->getDatas('thirdprogressed')), true);
        $horoscope = HoroscopeData::getInstance(['recode' => $recode, 'time_start' => 23, 'time_type' => 0, 'advance' => $timeinfo])->getUserData();
        foreach ($fortune_list as $k1 => $v1)
        {
            $sort = $v1['score'] / 100;
            switch ($v1['color'])
            {
                // 困难
                case '#7775ff':
                    $sort += 50;
                    break;
                // 警戒
                case '#ffa536':
                    $sort += 40;
                    break;
                // 平平
                case '#ffed17':
                    $sort += 30;
                    break;
                // 吉利
                case '#00f4e7':
                    $sort += 20;
                    break;
                // 大吉
                case '#00e9a0':
                    $sort += 10;
                    break;
            }
            $fortune_list[$k1]['sort'] = $sort;
        }
        // 运势柱状图按分值排序
        $resortFortuneList = resort($fortune_list, 'sort', 'DESC');
        $sex = $recode['type'] * 1;
        // 计算年龄
        $nowYear = date("Y", $time);
        $nowMonth = date("m", $time);
        $nowDay = date("d", $time);
        $birthYear = $recode['year'];
        $birthMonth = $recode['month'];
        $birthDay = $recode['day'];
        if ($nowMonth < $birthMonth)
        {
            $age = $nowYear - $birthYear - 1;
        } elseif ($nowMonth == $birthMonth)
        {
            if ($nowDay < $birthDay)
            {
                $age = $nowYear - $birthYear - 1;
            } else
            {
                $age = $nowYear - $birthYear;
            }
        } else
        {
            $age = $nowYear - $birthYear;
        }
        // 开始获取需要推荐的问题
        $qList = [
            0 => [
                'text' => '半年内，我的财运会好转吗？',
                'tab_index_default' => 1, // 1=>星盘,2=>骰子,3=>塔罗
                'is_force' => 1,// 是否不能切换
            ],
            1 => [
                'text' => '半年内，我能赚到很多钱吗？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            2 => [
                'text' => '半年内，我能发财吗？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            3 => [
                'text' => '半年内，我适不适合炒股投资？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            4 => [
                'text' => '半年内我能有桃花吗？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            5 => [
                'text' => '半年内我能遇到好的缘分吗？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            6 => [
                'text' => '我的另一半是什么样的？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            7 => [
                'text' => '什么样的人会喜欢我？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            8 => [
                'text' => '半年内，我的感情运能变好吗？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            9 => [
                'text' => '我目前喜欢的人喜欢我吗？',
                'tab_index_default' => 3,
                'is_force' => 0,
            ],
            10 => [
                'text' => '我该怎么和现在喜欢的人相处？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            11 => [
                'text' => '他还会回来找我吗？',
                'tab_index_default' => 3,
                'is_force' => 0,
            ],
            12 => [
                'text' => '我适合做什么工作？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            13 => [
                'text' => '半年内我能有好的事业发展吗？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            14 => [
                'text' => '半年内我有没有创业机会？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            15 => [
                'text' => '我的未来事业高度怎样？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
            16 => [
                'text' => '我最近适合换工作吗？',
                'tab_index_default' => 3,
                'is_force' => 0,
            ],
            17 => [
                'text' => '我目前要继续读书吗？',
                'tab_index_default' => 3,
                'is_force' => 0,
            ],
            18 => [
                'text' => '我现在需要学一些什么？',
                'tab_index_default' => 3,
                'is_force' => 0,
            ],
            19 => [
                'text' => '我适合学习占星吗？',
                'tab_index_default' => 1,
                'is_force' => 1,
            ],
        ];
        $questionList = [];
        if ($resortFortuneList[0]['name'] === '财富')
        {
            // 困难
            if ($resortFortuneList[0]['sort'] > 50 || $sex === 1)
            {
                $questionList[0] = [
                    'text' => $qList[0]['text'],
                    'sort' => 1,
                ];
            }
        }
        // 财运警戒以下
        if ($fortune_list[3]['sort'] > 40)
        {
            // 本命有三颗以上星在2宫 || 本命金星被土星刑冲
            if ($natal['houses'][2]['have_planet_num'] >= 3
                || (isset($natal['planets'][3]['phase']['3-6']) && in_array($natal['planets'][3]['phase']['3-6']['phase_e'], [90, 180], true)))
            {
                $questionList[1] = [
                    'text' => $qList[1]['text'],
                    'sort' => 1,
                ];
                $questionList[2] = [
                    'text' => $qList[2]['text'],
                    'sort' => 1,
                ];
            }
            // 本命有三颗以上星体在8宫 ||  八字天干或地支本气有劫财
            if ($natal['houses'][8]['have_planet_num'] >= 3
                || in_array('劫', $horoscope['shishen1'], true)
                || $horoscope['shishen2'][0][0] === '劫'
                || $horoscope['shishen2'][1][0] === '劫'
                || $horoscope['shishen2'][2][0] === '劫'
                || $horoscope['shishen2'][3][0] === '劫')
            {
                $questionList[3] = [
                    'text' => $qList[3]['text'],
                    'sort' => 1,
                ];
            }
        }
        // 婚恋平平以下
        if ($fortune_list[0]['sort'] > 30)
        {
            // 女
            if ($sex !== 1)
            {
                $questionList[4] = [
                    'text' => $qList[4]['text'],
                    'sort' => 1,
                ];
            }
            // 女 || 金星被土天海冥之一刑冲
            if ((isset($natal['planets'][3]['phase']['3-6']) && in_array($natal['planets'][3]['phase']['3-6']['phase_e'], [90, 180], true))
                || (isset($natal['planets'][3]['phase']['3-7']) && in_array($natal['planets'][3]['phase']['3-7']['phase_e'], [90, 180], true))
                || (isset($natal['planets'][3]['phase']['3-8']) && in_array($natal['planets'][3]['phase']['3-8']['phase_e'], [90, 180], true))
                || (isset($natal['planets'][3]['phase']['3-9']) && in_array($natal['planets'][3]['phase']['3-9']['phase_e'], [90, 180], true)))
            {
                $questionList[5] = [
                    'text' => $qList[5]['text'],
                    'sort' => 1,
                ];
            } elseif ($sex !== 1)
            {
                $questionList[5] = [
                    'text' => $qList[5]['text'],
                    'sort' => 1,
                ];
            }
            // 女 || 金星被土刑冲
            if (isset($natal['planets'][3]['phase']['3-6']) && in_array($natal['planets'][3]['phase']['3-6']['phase_e'], [90, 180], true))
            {
                $questionList[7] = [
                    'text' => $qList[7]['text'],
                    'sort' => 1,
                ];
            } elseif ($sex !== 1)
            {
                $questionList[7] = [
                    'text' => $qList[7]['text'],
                    'sort' => 1,
                ];
            }
            // 婚恋运警戒以下
            if ($fortune_list[0]['sort'] > 40)
            {
                $questionList[8] = [
                    'text' => $qList[8]['text'],
                    'sort' => 1,
                ];
            }
        }
        if ($age <= 22)
        {
            $questionList[6] = [
                'text' => $qList[6]['text'],
                'sort' => 0,
            ];
        }
        // 女，土星5宫或土星金星成相或土星火星成相，28岁以下 || 女22岁以下
        if ($sex !== 1)
        {
            if ($age <= 28 && ($natal['planets'][6]['in_house_id'] === 5
                    || isset($natal['planets'][6]['phase']['6-3'])
                    || isset($natal['planets'][6]['phase']['6-4'])))
            {
                $questionList[9] = [
                    'text' => $qList[9]['text'],
                    'sort' => 0,
                ];
            } elseif ($age <= 22)
            {
                $questionList[9] = [
                    'text' => $qList[9]['text'],
                    'sort' => 0,
                ];
            }
        }
        // 金星被任意星刑冲 || 月亮被任意星刑冲 || 婚恋60分以上
        $isVenu90180 = false;
        $isMoon90180 = false;
        if (!empty($natal['planets'][3]['phase']))
        {
            foreach ($natal['planets'][3]['phase'] as $phase)
            {
                if ($phase['id'] < 10 && in_array($phase['phase_e'], [90, 180], true))
                {
                    $isVenu90180 = true;
                    break;
                }
            }
        }
        if (!empty($natal['planets'][1]['phase']))
        {
            foreach ($natal['planets'][1]['phase'] as $phase)
            {
                if ($phase['id'] < 10 && in_array($phase['phase_e'], [90, 180], true))
                {
                    $isMoon90180 = true;
                    break;
                }
            }
        }
        if ($isVenu90180 || $isMoon90180)
        {
            $questionList[10] = [
                'text' => $qList[10]['text'],
                'sort' => 0,
            ];
        } elseif ($fortune_list[0]['score'] >= 60)
        {
            $questionList[10] = [
                'text' => $qList[10]['text'],
                'sort' => 0,
            ];
        }
        if ($sex !== 1)
        {
            // 日月升金火之一在巨蟹或双鱼，婚恋警戒以下 || 三限金星刑冲冥王，本命日月升金火之一在双鱼或巨蟹或金星与海王成相
            if ($fortune_list[0]['score'] > 40
                && (in_array($natal['planets'][0]['in_sign_id'], [4, 12], true)
                    || in_array($natal['planets'][1]['in_sign_id'], [4, 12], true)
                    || in_array($natal['planets'][ASC]['in_sign_id'], [4, 12], true)
                    || in_array($natal['planets'][3]['in_sign_id'], [4, 12], true)
                    || in_array($natal['planets'][4]['in_sign_id'], [4, 12], true)))
            {
                $questionList[11] = [
                    'text' => $qList[11]['text'],
                    'sort' => 0,
                ];
            } elseif (isset($thirdprogressed['planets'][3]['phase']['3-9'])
                && in_array($thirdprogressed['planets'][3]['phase']['3-9']['phase_e'], [90, 180], true)
                && (in_array($natal['planets'][0]['in_sign_id'], [4, 12], true)
                    || in_array($natal['planets'][1]['in_sign_id'], [4, 12], true)
                    || in_array($natal['planets'][ASC]['in_sign_id'], [4, 12], true)
                    || in_array($natal['planets'][3]['in_sign_id'], [4, 12], true)
                    || in_array($natal['planets'][4]['in_sign_id'], [4, 12], true)
                    || isset($natal['planets'][3]['phase']['3-8'])))
            {
                $questionList[11] = [
                    'text' => $qList[11]['text'],
                    'sort' => 1,
                ];
            }
        }
        // 事业运警戒以下
        if ($fortune_list[2]['sort'] > 40)
        {
            // 20岁以上，24岁以下
            if ($age >= 20 && $age <= 24)
            {
                $questionList[12] = [
                    'text' => $qList[12]['text'],
                    'sort' => 0,
                ];
            }
            // 男 || 女，事业运第一且警戒以下
            if ($sex === 1 || ($sex !== 1 && $resortFortuneList[0]['name'] === '工作'))
            {
                $questionList[13] = [
                    'text' => $qList[13]['text'],
                    'sort' => 0,
                ];
            }
        }
        // 八字原局有七杀或本气七杀
        if (in_array('杀', $horoscope['shishen1'], true)
            || $horoscope['shishen2'][0][0] === '杀'
            || $horoscope['shishen2'][1][0] === '杀'
            || $horoscope['shishen2'][2][0] === '杀'
            || $horoscope['shishen2'][3][0] === '杀')
        {
            $questionList[14] = [
                'text' => $qList[14]['text'],
                'sort' => 0,
            ];
        }
        // 日月金木水火土之一在10宫 || 八字有官杀或本气官杀
        if ($sex === 1
            && ($natal['planets'][0]['in_house_id'] === 10
                || $natal['planets'][1]['in_house_id'] === 10
                || $natal['planets'][2]['in_house_id'] === 10
                || $natal['planets'][3]['in_house_id'] === 10
                || $natal['planets'][4]['in_house_id'] === 10
                || $natal['planets'][5]['in_house_id'] === 10
                || $natal['planets'][6]['in_house_id'] === 10
                || in_array('杀', $horoscope['shishen1'], true)
                || in_array('官', $horoscope['shishen1'], true)
                || in_array($horoscope['shishen2'][0][0], ['官', '杀'], true)
                || in_array($horoscope['shishen2'][1][0], ['官', '杀'], true)
                || in_array($horoscope['shishen2'][2][0], ['官', '杀'], true)
                || in_array($horoscope['shishen2'][3][0], ['官', '杀'], true)))
        {
            $questionList[15] = [
                'text' => $qList[15]['text'],
                'sort' => 0,
            ];
        }
        // 三限月亮与天王海王同时成相位 || 三限月亮在6/8/10宫与天王或海王成相
        if ((isset($thirdprogressed['planets'][1]['phase']['1-7'], $thirdprogressed['planets'][1]['phase']['1-8']))
            || (in_array($thirdprogressed['planets'][1]['in_house_id'], [6, 8, 10], true)
                && (isset($thirdprogressed['planets'][1]['phase']['1-7']) || isset($thirdprogressed['planets'][1]['phase']['1-8']))))
        {
            $questionList[16] = [
                'text' => $qList[16]['text'],
                'sort' => 1,
            ];
        }
        // 23岁以上，日月木土之一在9宫
        if ($age >= 23 && ($natal['planets'][0]['in_house_id'] === 9
                || $natal['planets'][1]['in_house_id'] === 9
                || $natal['planets'][5]['in_house_id'] === 9
                || $natal['planets'][6]['in_house_id'] === 9))
        {
            $questionList[17] = [
                'text' => $qList[17]['text'],
                'sort' => 0,
            ];
        }
        // 土星在39宫 || 本命日月升之一在双子座
        if (in_array($natal['planets'][6]['in_house_id'], [3, 9], true)
            || $natal['planets'][0]['in_sign_id'] === 3
            || $natal['planets'][1]['in_sign_id'] === 3
            || $natal['planets'][ASC]['in_sign_id'] === 3)
        {
            $questionList[18] = [
                'text' => $qList[18]['text'],
                'sort' => 0,
            ];
        }
        // 本命日月升有处女、天蝎、水瓶、双鱼之一，89或12宫有日月水命主之一 || 本命水星落8宫
        if ($natal['planets'][2]['in_house_id'] === 8
            && (
                (in_array($natal['planets'][0]['in_sign_id'], [6, 8, 11, 12], true)
                    || in_array($natal['planets'][1]['in_sign_id'], [6, 8, 11, 12], true)
                    || in_array($natal['planets'][ASC]['in_sign_id'], [6, 8, 11, 12], true))
                && (
                    in_array($natal['planets'][0]['in_house_id'], [8, 9, 12], true)
                    || in_array($natal['planets'][1]['in_house_id'], [8, 9, 12], true)
                    || in_array($natal['planets'][2]['in_house_id'], [8, 9, 12], true)
                    || in_array($natal['houses'][1]['protect_ancient_inhouse_id'], [8, 9, 12], true))))
        {
            $questionList[19] = [
                'text' => $qList[19]['text'],
                'sort' => 0,
            ];
        }
        $questionListResort = resort(array_values($questionList), 'sort', 'DESC');
        $qTextList = array_column($qList, 'text');
        $arr = array_slice($questionListResort, 0, 5);
        $arr = array_column($arr, 'text');
        $count = count($arr);
        $max = 5;
        if ($count < $max)
        {
            // 不够5个，需要补充
            $need = $max - $count;
            $diffArr = array_diff($qTextList, $arr);
            $diffArr = array_values($diffArr);
            $countDiff = count($diffArr);
            $index = date('d', $time) % $countDiff;
            $slice = array_slice($diffArr, $index, $need);
            $arr = array_merge($arr, $slice);
        }

        $result = [];
        foreach ($arr as $k => $v)
        {
            $index = array_search($v, $qTextList, true);
            $result[] = [
                'text' => $qList[$index]['text'],
                'target' => 'local',
                'link' => 'question_answer_add?qid=0&qtype=3&title=' . urlencode($v) . '&tab_index_default=' . $qList[$index]['tab_index_default'] . '&is_force=' . $qList[$index]['is_force'] . '&need_auth=2',
            ];
        }

        return $result;
    }
}
